<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="订单号">
              <el-input v-model="params.order_sn" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名/手机号">
              <el-input v-model="params.keyword" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单状态">
              <el-select v-model="params.order_status" placeholder="请选择" clearable>
                <el-option
                  v-for="item in codeType"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单下单时间">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单支付时间">
              <el-date-picker
                v-model="time1"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="上级姓名/手机号">
              <el-input v-model="params.server_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <!-- 新加 -->
            <!-- <el-button style="margin-left:60px" type="primary" @click="exfun">导出</el-button> -->
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="listDiv">
      <!-- {{$store.state.user.permissionJson}} -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        />
        <el-table-column prop="order_sn" label="订单编号" align="center" />
        <el-table-column prop="realname" label="姓名" align="center" />
        <el-table-column prop="user_phone" label="手机号" align="center">
          <template slot-scope="scope">
            <div>{{scope.row.server_phone | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="server_name" label="上级姓名" align="center" />
        <el-table-column prop="server_phone" label="上级手机号" align="center">
          <template slot-scope="scope">
            <div>{{scope.row.server_phone | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="goods_name" label="购买卡/券" align="center" />
        <el-table-column prop="type_name" label="优惠券名称" align="center" />
        <el-table-column prop="check_status_name" label="卡券状态" align="center" />
        <el-table-column prop="pay_type_name" label="支付方式" align="center" />
        <el-table-column prop="order_price" label="现金支付" align="center" />
        <el-table-column prop="gold_credit" label="金币支付" align="center" />
        <el-table-column prop="silver_credit" label="银币支付" align="center" />
        <el-table-column prop="queue" label="核销顺序" align="center" />
        <el-table-column prop="hospital_name" label="核销医院" align="center" />
        <!-- <el-table-column prop="is_up_name" label="是否升单" align="center" /> -->
        <el-table-column prop="project_order_sn" label="流水单编号" align="center" />
        <el-table-column prop="checked_at" label="核销时间" align="center">
          <template slot-scope="scope">{{ scope.row.checked_at*1000 | date(1) }}</template>
        </el-table-column>
        <el-table-column prop="settle_money" label="结算金额" align="center" />
      </el-table>
      <el-pagination
        :current-page="params.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
// src\api\Cardreward\index.js
import filter from "@/assets/filter";
import { c2c_check, get_order_status_name } from "@/api/Cardreward/index";
import { exportfile } from "@/api/commjs/exprot";
export default {
  name: "",
  data() {
    return {
      total: 0,
      time: "",
      tableData: [],
      codeType: [],
      time1: "",
      params: { page: 1, size: 10 }
    };
  },
  watch: {
    time(val) {
      this.params.pay_time_start = val ? val[0] : "";
      this.params.pay_time_end = val ? val[1] : "";
    },
    time1(val) {
      this.params.order_time_start = val ? val[0] : "";
      this.params.order_time_end = val ? val[1] : "";
    }
  },
  created() {
    this.list();
    this.codefn();
  },
  methods: {
    async codefn() {
      const res = await get_order_status_name();
      if (res.data.code == 200) {
        this.codeType = res.data.data;
      }
    },
    searchFn() {
      this.params.page = 1;
      this.list();
    },
    async list() {
      const res = await c2c_check(this.params);
      console.log(res);
      if (res.data.code == 200) {
        this.tableData = res.data.data;
        this.total = res.data.meta.total;
      }
    },
    table_index(index) {
      return (this.params.page - 1) * this.params.size + index + 1;
    },
    handleSizeChange(val) {
      this.params.page = 1;
      this.params.size = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.page = val;
      this.list();
    },
    exfun() {
      exportfile(
        "/com.mmk.reservation.api.AdminHospitalAccountProvider/1.0.0/hospitalAccountRechargeexport.html",
        this.params
      );
    }
  }
};
</script>
